"use strict";
/* Controllers */
app.controller("userGroupAddController", ['$scope', '$location', '$rootScope', '$routeParams', 'userGroupAddService', function ($scope, $location, $rootScope, $routeParams, userGroupAddService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.p.id = $routeParams.id; // 如果ID!=0为更新

    var errorFn = function (result) {
        alert(result);
    };
    $scope.addUserGroup = function () {
        var vm = $scope.vm;
        var param = vm.p
//        var users = {
//            id: vm.p.id,
//            userName: vm.p.userName,
//            userCn: vm.p.userCn,
//            email: vm.p.email,
//            mobile: vm.p.mobile,
//            isTest: vm.p.isTestDefine.id,
//            leader: vm.p.leader
//        };
        var procFn = function (response) {
            if (response.success && response.data) {
                //window.location = "#/income/user_list/0";
                alert("执行成功！")
            } else {
                alert(response.msg);
            }
        };
        userGroupAddService.addUseGroup(param, procFn, errorFn);
    };

    if(vm.p.id!=0) {
        var param = {
            id: vm.p.id
        };
        var procFn = function (response) {
            if (response.success && response.data) {
                vm.p = response.data;
            } else {
                alert(response.message);
            }
        };
        userGroupAddService.getUserGroup(param, procFn, errorFn);
    }else {
//        vm.p.isTestDefine = selectIsTestDefine(0);
    }

}]);


/* Services */
app.service('userGroupAddService', ['ajaxService', function (ajaxService) {

    this.addUseGroup = function (users, successFunction, errorFunction) {
        ajaxService.AjaxPost(users, "/star/api/basic-service/v1/userGroup/setUserGroup.do", successFunction, errorFunction);
    };

    this.getUserGroup = function (users, successFunction, errorFunction) {
        ajaxService.AjaxPost(users, "/star/api/basic-service/v1/userGroup/detail.do", successFunction, errorFunction);
    };

}]);

